<?php
class Tag_model extends CI_Model {
	public function add_tags($pid,$tags){
		$data = array();
		$tags = array_flip(array_flip($tags));
		foreach ($tags as $t){
			if($t){
				array_push($data,array('pid'=>$pid,'text'=>$t,));
			}
		}
		if(count($data)){
			$this->db->insert_batch('tag', $data);
		}
	}
	
	public function get_tags_array($pid){
		$this->db->where('pid',$pid);
		$this->db->select('text');
		$this->db->distinct();
		$query = $this->db->get('tag');
		return $query->result_array();
	}
	
	public function get_focus_tags($uid){
		$this->db->where('uid',$uid);
		$this->db->select('tag');
		$this->db->distinct();
		$query = $this->db->get('focus');
		return $query->result_array();
	}
	
	public function update_focus($uid,$tags){
		
		$this->db->delete('focus',array('uid'=>$uid));
		
		$data = array();
		$tags = array_flip(array_flip($tags));
		foreach ($tags as $t){
			if($t){
				array_push($data,array('uid'=>$uid,'tag'=>$t,));
			}
		}
		if(count($data)){
			$this->db->insert_batch('focus', $data);
		}
	}
}
?>